package matt.design;

/**
 * This class creates the User's database and handles modifications to it also
 */
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class UserSQLiteHelper extends SQLiteOpenHelper {

	public static final String TABLE_USERS = "users";
	//public static final String COLUMN_ID = "_id";
	public static final String COLUMN_ID = "email";				// The user's email with be the UID in the datab
	public static final String COLUMN_FIRST = "first";
	public static final String COLUMN_LAST = "last";
	public static final String COLUMN_PASSWORD = "password";
	public static final String COLUMN_COMMENT = "comment";

	private static final String DATABASE_NAME = "users.db";
	private static final int DATABASE_VERSION = 1;
	
	private static final String DATABASE_CREATE = "create table " + TABLE_USERS + "( " 
			+ COLUMN_ID + " text primary key, "
			+ COLUMN_FIRST + " text not null, "
			+ COLUMN_LAST + " text not null, "
			+ COLUMN_PASSWORD + " text not null);";
	/**
	 * Method that takes in context and then the database name and version in order to locate the current database
	 * @param context
	 */
	public UserSQLiteHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}
	
	/**
	 * Method that actually creates the columns and labels of the columns in the database
	 */
	@Override
	public void onCreate(SQLiteDatabase database) {
		database.execSQL(DATABASE_CREATE);
	}

	/**
	 * Upgrades the database with new information
	 */
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(UserSQLiteHelper.class.getName(),
				"Upgrading database from version " + oldVersion + " to "
						+ newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS" + TABLE_USERS);
		onCreate(db);
	}

}
